#!/bin/sh
arch=dotgnat
cd image 
find * -name $arch -type d                           | tr / "\\" 2>/dev/null >../targetdirlist.tmp
find * -type d                                       | tr / "\\" 2>/dev/null >../dirlist.tmp
find * -name $arch -type d -prune -false -or -type f | tr / "\\" 2>/dev/null >../filelist.tmp
cd ..
cat targetdirlist.tmp | sed -e "s#\(.*\)#SetOutPath \"\$0\\\\\1\"\nFile /a /r \"image\\\\\1\\\\*.*\" #" > imageinstall.nsi
echo "SetOutPath \"\$0\"" >> imageinstall.nsi
cat dirlist.tmp | sed -e "s#\(.*\)#CreateDirectory \"\$0\\\\\1\"#" >> imageinstall.nsi
cat filelist.tmp | sed -e "s#\(.*\)#File /a \"/oname=\1\" \"image\\\\\1\"#" >> imageinstall.nsi
cat targetdirlist.tmp | sed -e "s#\(.*\)#RmDir /r \"\$INSTDIR\\\\\1\"#" > imageuninstall.nsi
cat filelist.tmp      | sed -e "s#\(.*\)#Delete \"\$INSTDIR\\\\\1\"#" >> imageuninstall.nsi
cat dirlist.tmp | sort -r | sed -e "s#\(.*\)#RmDir \"\$INSTDIR\\\\\1\"#" >> imageuninstall.nsi
rm *.tmp